//
// Created by glyn on 2024/3/22.
//

#include <iostream>
#include "gtlv.hpp"

//定义字符串类型
//defining string types
#define STRINGTYPE 32

int main()
{

    int8_t data[128] = {0};
    gtlv head;
    gtlv em((int32_t) STRINGTYPE,std::string("Hello gTLV!") );
    head.addtlv(em);
    head.addtlv(em);
    head.addtlv(em);

    for (auto it:head.tlvObj())
    {
        std::cout << it.getType() << std::endl;

        std::cout << it.getLen() << std::endl;

        std::cout << it.getstring() << std::endl;

    }
    std::cout << "------------------------------------------" << std::endl;

    //序列化
    //serialization
    auto len= head.serialization(data,0);

    //反序列化
    //deserialization
    gtlv headout;
    headout.deserialization(data,0);

    for (auto it:headout.tlvObj())
    {
        std::cout << it.getType() << std::endl;

        std::cout << it.getLen() << std::endl;

        std::cout << it.getstring() << std::endl;

    }

    return 0;
}